﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using WeifenLuo.WinFormsUI.Docking;
using System.Net;
using System.IO;
using System.Web;

namespace Vote17173
{
	public partial class Form1 : DockContent
	{
		public Form1()
		{
			InitializeComponent();
		}

		private void btnVote_Click(object sender, EventArgs e)
		{
			Encoding eEncoding = Encoding.GetEncoding("gbk");
			CookieContainer cc = new CookieContainer();

			string strYear = DateTime.Now.Year.ToString();
			string inData = string.Format("vote_id={1}&vote_year={3}&vote_item_{1}={2}&vote_submit=%CD%B6%C6%B1%2F%B2%E9%BF%B4%BD%E1%B9%FB", "投票/查看结果", txtVoteID.Text, txtVoteItemID.Text, strYear);

			string outdata = "";
			System.Net.HttpWebRequest hwRequest = (System.Net.HttpWebRequest)WebRequest.Create("http://vote.17173.com/action/vote_process.php");
			hwRequest.Host = "vote.17173.com";
			hwRequest.KeepAlive = true;
			hwRequest.Referer = "http://vote.17173.com/index.php";
			hwRequest.Headers.Add("Origin", "http://vote.17173.com");
			hwRequest.ContentType = "application/x-www-form-urlencoded";
			hwRequest.Method = "POST";
			hwRequest.CookieContainer = cc;
			Stream hwrStream = hwRequest.GetRequestStream();
			StreamWriter sw = new StreamWriter(hwrStream, eEncoding);
			sw.Write(inData);
			sw.Flush();
			sw.Close();
			hwrStream.Flush();
			hwrStream.Close();

			HttpWebResponse myHttpWebResponse = (HttpWebResponse)hwRequest.GetResponse();
			try
			{
				eEncoding = Encoding.GetEncoding(myHttpWebResponse.ContentEncoding);
			}
			catch { }
			myHttpWebResponse.Cookies = cc.GetCookies(hwRequest.RequestUri);
			Stream myResponseStream = myHttpWebResponse.GetResponseStream();
			StreamReader myStreamReader = new StreamReader(myResponseStream, eEncoding);
			outdata = myStreamReader.ReadToEnd();
			myStreamReader.Close();
			myResponseStream.Close();

			txtResponse.Text = outdata;
		}

		private void Form1_Load(object sender, EventArgs e)
		{

		}
	}
}
